var $$ = jQuery.noConflict();
(function ($, doc) {
    document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + 'px';
    $.init();
    $.ready(function () {
        console.log(sourceType)
        localStorage.setItem('sourceType',sourceType)
        var data = {}
        if(!sourceType){
            //phone or key
            var hrefStr=window.location.href.indexOf('Apply')
            var hrefStr1=window.location.href.substring(hrefStr+5)
            //用户信息
            var urldata={}
            urldata.url=hrefStr1
            localStorage.setItem('urldata',JSON.stringify(urldata))
        }
        //form表单
        $$('#send').on('touchend', function () {
            var i = 0;
            mui("#formData input").each(function () {
                if (!this.value || this.value.trim() == "") {
                    var label = this.previousElementSibling;
                    mui.alert(label.innerText + "不允许为空");
                    return false;
                } else {
                    i = i + 1
                }
            });
            if (i == 8) {
                ifelse()
            }
        })
        function ifelse() {
            if (/^[a-z0-9A-Z]{5}$/.test($$('#yqm').val())) {
                if (/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test($$('#phone').val())) {
                    data.education = $$("#formData input").eq(0).val()
                    data.advertisement =  $$("#formData input").eq(1).val()
                    data.address =  $$("#formData input").eq(2).val()+ $$("#formData input").eq(3).val()
                    data.contactName = $$("#formData input").eq(5).val()
                    data.contactPhone =  $$("#formData input").eq(6).val()
                    data.contactRelation =  $$("#formData input").eq(7).val()
                    localStorage.setItem('userInfo',JSON.stringify(data))
                    openPage('/member/next')
                } else {
                    mui.alert("请输入正确手机号")
                }
            } else {
                mui.alert("请输入正确5位邀请码");
            }
        }
        //选择框关系
        var userPicker2 = new $.PopPicker();
        userPicker2.setData([{
            value: 'gzx',
            text: '高中以下'
        }, {
            value: 'gz',
            text: '高中'
        }, {
            value: 'zk',
            text: '专科'
        }, {
            value: 'bk',
            text: '本科'
        }, {
            value: 'ss',
            text: '硕士研究生'
        }, {
            value: 'bs',
            text: '博士研究生'
        }]);
        var checkstudy = doc.getElementById('checkstudy');
        var studyShow = doc.getElementById('studyShow');
        checkstudy.addEventListener('tap', function (event) {
            userPicker2.show(function (items) {
                studyShow.value = items[0].text
                //返回 false 可以阻止选择框的关闭
                //return false;
            });
        }, false);

        //选择框关系
        var userPicker = new $.PopPicker();
        userPicker.setData([{
            value: 'fm',
            text: '父母'
        }, {
            value: 'ts',
            text: '同事'
        }, {
            value: 'py',
            text: '朋友'
        }, {
            value: 'po',
            text: '配偶'
        }]);
        var checkRelation = doc.getElementById('checkRelation');
        var relationShow = doc.getElementById('relationShow');
        checkRelation.addEventListener('tap', function (event) {
            userPicker.show(function (items) {
                relationShow.value = items[0].text
                //返回 false 可以阻止选择框的关闭
                //return false;
            });
        }, false);

        var cityPicker3 = new $.PopPicker({
            layer: 3
        });
        cityPicker3.setData(cityData3);
        var showCityPickerButton = doc.getElementById('checkAdress');
        var adressShow = doc.getElementById('adressShow');
        showCityPickerButton.addEventListener('tap', function (event) {
            cityPicker3.show(function (items) {
                adressShow.value = (items[0] || {}).text + " " + (items[1] || {}).text + " " + (items[2] || {}).text;
                //返回 false 可以阻止选择框的关闭
                //return false;
            });
        }, false)
    });
})(mui, document);